package singleton;

public class Singleton2 {
    private static Singleton2 instance = null;

    public static Singleton2 getInstance() {
        if (instance == null) {
            instance = new Singleton2();
        }
        return instance;
    }

    public static synchronized Singleton2 getInstance1() {
        if (instance == null) {
            instance = new Singleton2();
        }
        return instance;
    }

    public static Singleton2 getInstance2() {
        if (instance == null) {
            synchronized (Singleton2.class) {
                if (instance == null) {
                    instance = new Singleton2();
                }
            }
        }
        return instance;
    }

    private static volatile Singleton2 instance1 = null;

    public static Singleton2 getInstance3() {
        if (instance1 == null) {
            synchronized (Singleton2.class) {
                if (instance1 == null) {
                    instance1 = new Singleton2();
                }
            }
        }
        return instance1;
    }
}
